![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
estree-builder
Advanced tools
Handy functions for building estree nodes
var e = require('estree-builder')
var estree = e.number(1)
// -> { type: 'Literal', value: 1 }
//let's use astring to convert the estree into js code
var astring = require('astring').generate
astring(estree)
// -> '1'
estree = e.fn(['a', 'b'], [
e('return', e('+', e.id('a'), e.id('b')))
], 'add')
astring(estree)
// -> 'function add(a, b) {return a + b}'
There are 3 ways to call a builder
e.number(1)
e['number'](1)
e('number', 1)
All builders can take a location
object as the last argument. (i.e. for generating source maps)
var loc = {
source: "some-file.js"
start: { line: 1, column: 0 },
end: { line: 1, column: 1 }
}
e('number', 1, loc)
e('number', val) //aliases: 'num', 'float'
e('string', val) //aliases: 'str'
e('true')
e('false')
e('null')
e('undefined') //aliases: 'nil'
e('array', elements) //aliases: 'arr'
e('object-raw', pairs) //aliases: 'obj-raw'
e('object-property', key, value) //aliases: 'obj-prop'
e('object', obj) //aliases: 'obj'
e('json', val)
e('var', id, val)
e('let', id, val)
e('const', id, val)
e('identifier', name) //aliases: 'id'
e('if', test, consequent, alternate)
e('ternary', test, consequent, alternate) //aliases: '?'
e('switch', discriminant, cases)
e('case', test, consequent)
e('default', consequent)
e('while', test, body)
e('for', init, test, update, body)
e('for-in', left, right, body)
e('for-of', left, right, body)
e('break')
e('continue')
e('return', arg)
e('throw', arg)
e('try', body, catchVar, catchStmt, finallyStmt)
e('function', args, body, id) //aliases: 'fn', 'lambda'
e('call', callee, args)
e('arrow', args, body)
e('.', obj, prop)
e('get', obj, prop)
e('get-in', obj, path) //aliases: '..'
e('arguments') //aliases: 'args'
e('this')
e('statement', expr) //aliases: ';'
e('block', body)
e('new', callee, args)
e('==', left, right)
e('!=', left, right)
e('===', left, right)
e('!==', left, right)
e('<', left, right)
e('<=', left, right)
e('>', left, right)
e('>=', left, right)
e('<<', left, right)
e('>>', left, right)
e('>>>', left, right)
e('*', left, right)
e('/', left, right)
e('%', left, right)
e('|', left, right)
e('^', left, right)
e('&', left, right)
e('in', left, right)
e('instanceof', left, right)
e('&&', left, right)
e('||', left, right)
e('+', a, b)
e('-', a, b)
e('!', arg)
e('~', arg)
e('typeof', arg)
e('void', arg)
e('delete', arg)
e('++', arg)
e('--', arg)
e('=', left, right)
e('+=', left, right)
e('-=', left, right)
e('*=', left, right)
e('/=', left, right)
e('%=', left, right)
e('<<=', left, right)
e('>>=', left, right)
e('>>>=', left, right)
e('|=', left, right)
e('^=', left, right)
e('&=', left, right)
e('assign', left, right)
e('assign-property', key, value) //aliases: 'assign-prop'
e('obj-pattern', properties)
e('arr-pattern', elements)
e('genfn', args, body, id)
e('yield', arg, delegate)
e('class', name, superClass, methods)
e('method', key, value, kind, computed, isStatic)
Add tests to tests.js, run them like this:
$ npm test
or to automatically re-run them whenever you make a change
$ npm start
Re-generate the docs (README.md between the GEN-DOCS-BEGIN|END comments)
$ npm run build
MIT
FAQs
Handy functions for building estree nodes
The npm package estree-builder receives a total of 130 weekly downloads. As such, estree-builder popularity was classified as not popular.
We found that estree-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.